package Hotel;

import java.util.Scanner;

public class Hotel {
	private String name;
	private Room[][] rooms;
	
	public Hotel(String name,int r, int c){  //构造
		this.name=name;
		this.rooms=new Room[r][c];			
		for(int i=0; i<rooms.length; i++){
			for(int j=0; j<rooms[i].length; j++){
				rooms[i][j]=new Room((i+1)*100+(j+1));         //构造了这么多的房间，都把他们放在二维数组里
			}
		}
	}
	
	public void in(int roomid,Guest g){
		int i=roomid/100-1;
		int j=roomid%100-1;
		if(i<0 || i>rooms.length-1 || j<0 || j>rooms[0].length){
			System.out.println("无效的房间");
			return;
		}
		if(rooms[i][j].checkin(g)){
			System.out.println(g.getName()+"入住成功");
		}else {
			System.out.println(g.getName()+"入住失败");
		}
	}
	
	public void out(int roomid){
		int i=roomid/100-1;
		int j=roomid%100-1;
		if(i<0 || i>rooms.length-1 || j<0 || j>rooms[0].length){
			System.out.println("无效的房间");
			return;		
		}
		if(rooms[i][j].checkout()){
			System.out.println("退房成功！欢迎下次光临！");
		}else {
			System.out.println("退房失败！");
		}
		}
	
	public void search(){
		for(int i=0 ;i<rooms.length; i++ ){
			for(int j=0; j<rooms[i].length; j++){
				System.out.print(rooms[i][j].toString()+"\t");
			}
			System.out.println();
			System.out.println();
		}
	}
		
	public void quit(){
		System.out.println("你已成功退出系统！");
		System.exit(0);
	}
	
	public void start(){
		Scanner sca=new Scanner(System.in);
		System.out.println("Welcome to "+name+",Please enter your command:");
		while(true){
			
			String comm=sca.next();
			if(comm.equals("search")){
				System.out.println("room state：");
				search();
			}else if(comm.equals("in")){			
				System.out.println("Please enter room id：");
				int roomid=sca.nextInt();				
				System.out.println("Please enter guset name：");
				String gName=sca.next();
				System.out.println("Please enter guset ID：");
				String gId=sca.next();
				Guest g=new Guest(gName,gId);
				in(roomid,g);				
			}else if(comm.equals("out")){
				System.out.println("清输入要退房的房间号;");
				int roomid=sca.nextInt();
				out(roomid);
				
			}else if(comm.equals("quit")){
				quit();
			}else {
				
			}
		}
	}

}

